/* eslint-disable */
// 获取元素内容尺寸
export function getWh (el, name) {
  let val = name === 'width' ? el.offsetWidth : el.offsetHeight
  let which = name === 'width' ? ['left', 'Right'] : ['Top', 'Bottom']
  if (val === 0) {
    return 0
  }
  let style = getStyle(el)
  // 左右或上下两边的都减去
  for (let i = 0, a; a = which[i++];) {
    val -= parseFloat(style['border' + a + 'Width']) || 0
    val -= parseFloat(style['padding' + a ]) || 0
  }
  return val  
  // 考虑 IE 的兼容性
  function getStyle (el) {
    if (window.getComputedStyle) {
      return window.getComputedStyle(el, null)
    } else {
      return el.currentStyle
    }
  }
}

// 获取元素位置
export function getPosition (el, name){
  name = name.toLowerCase().replace('left', 'Left').replace('top', 'Top')
  var offset = 'offset' + name
  var actualLeft = el[offset]
  var current = el.offsetParent
  while (current !== null) {
    actualLeft += current[offset]
    current = current.offsetParent
  }
  return actualLeft
}
